﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.DataManagementTools;
using ESRI.ArcGIS.SpatialAnalyst;
using ESRI.ArcGIS.DataSourcesRaster;
using ESRI.ArcGIS.GeoAnalyst;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;

namespace WindowsFormsApp1
{
    public partial class Form3 : Form
    {
        IRasterLayer startRasterLayer;
        IRasterLayer endRasterLayer;
        IRasterLayer costRasterLayer;
        IRasterLayer outRasterLayer;
        public MyDelegate myEvent;
        public Form3()
        {
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox_Start_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox_Start_Click(object sender, EventArgs e)
        {
            String name = null;
            startRasterLayer = MyTools.OpenDEM("添加dem对象", ref name);
            textBox_Start.Text = name;
        }

        private void textBox_End_Click(object sender, EventArgs e)
        {
            String name = null;
            endRasterLayer = MyTools.OpenDEM("添加dem对象", ref name);
            textBox_End.Text = name;
        }

        private void textBox_DEM_Click(object sender, EventArgs e)
        {
            String name = null;
            costRasterLayer = MyTools.OpenDEM("添加dem对象", ref name);
            textBox_DEM.Text = name;
        }

        private void textBox_Out_Click(object sender, EventArgs e)
        {
            textBox_Out.Text = MyTools.OpenBrowser("指定存放位置");
        }

        private void button_Start_Click(object sender, EventArgs e)
        {
            if(textBox_name.Text == "")
            {
                MessageBox.Show("文件名不能为空");
                return;
            }
            
            string name = textBox_Out.Text +"\\" + textBox_name.Text;
            /*
            if (!System.IO.Directory.Exists(name))
            {
                //创建pic文件夹
                System.IO.Directory.CreateDirectory(name);
            }
            name = name + "\\" + textBox_name.Text;
            */
            button_Start.Enabled = false;
            outRasterLayer = MyTools.CalMinPath(startRasterLayer, endRasterLayer, costRasterLayer, name);
            myEvent(outRasterLayer);
            this.Close();
        }
    }
}
